package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 字典大类表
 *
 * @author zhengyr*/
@Data
@Entity
@SQLDelete(sql = "update t_it_dict_data set dict_deleted = UNIX_TIMESTAMP(NOW()) where dict_id=?")
@SQLDeleteAll(sql = "update t_it_dict_data set dict_deleted = UNIX_TIMESTAMP(NOW()) where dict_id=?")
@Where(clause = "dict_deleted = 0")
@Table(name = "t_it_dict_data",uniqueConstraints = {@UniqueConstraint(columnNames={"dict_data", "dict_deleted"})})

public class ItDictData implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "dict_id")
    private Integer dictId;

    /**
     * 字典名称
     */
    @ApiModelProperty(value = "字典名称")
    @Column(name = "dict_name", columnDefinition = "varchar(30) COMMENT '字典名称'")
    private String dictName;

    /**
     * 字典代码
     */
    @ApiModelProperty(value = "字典代码")
    @Column(name = "dict_data", columnDefinition = "varchar(50) COMMENT '字典代码'")
    private String dictData;

    /**
     * 字典子项 一对多，外键维护在多的一方。name属性是多的一方指向本表的外键  referencedColumnName默认是本表的唯一id列，加上的时候可以指定一列，被多的一方关联
     */
    @ApiModelProperty(value = "字典子项数组")
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "dict_entry",referencedColumnName = "dict_data", foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    @OrderBy(value="seq ASC")
    private List<ItDict> dictValues;

    @Column(name = "dict_deleted", columnDefinition = "int COMMENT '删除状态（0=未删除(默认))'")
    private Long deleted = 0L;

    /**
     * 备注
     */
    @Column(name = "description", columnDefinition = "varchar(100) COMMENT '备注'")
    @ApiModelProperty(value = "备注")
    private String description;

    /**
     * 父级字典的dict_data
     */
    @ApiModelProperty(value = "关联的父级字典")
    @Column(name = "parent_code", columnDefinition = "varchar(64) COMMENT '字典项的父dict_data'")
    private String parentCode;

    /**
     * 关联的父级字典的字典子项数组
     */
    @Transient
    @ApiModelProperty(value = "关联的父级字典子项数组")
    private List<ItDict> parentDictValues = new ArrayList<>();

}
